package com.zjh.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.oas.annotations.EnableOpenApi;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

import java.util.ArrayList;


@Configuration
public class SwaggerConfig {

    @Value("${spring.profiles.active}")
    private String act;
    boolean isEnable;

    //协同开发
    @Bean
    public Docket docket1() {
        return new Docket(DocumentationType.SWAGGER_2).groupName("A");
    }

    @Bean
    public Docket docket2() {
        return new Docket(DocumentationType.SWAGGER_2).groupName("B");
    }

    @Bean
    public Docket docket3() {
        return new Docket(DocumentationType.SWAGGER_2).groupName("C");
    }

    @Bean
    public Docket docket() {

        if (act.equals("dev")) {
            isEnable = true;
        } else {
            isEnable = false;
        }

        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                .groupName("zzzzz")
                .enable(isEnable)
                .groupName("这是组名")
                .select()
                // RequestHandlerSelectors 配置要扫描接口的方式
                // basePackage 指定要扫描的包
                .apis(RequestHandlerSelectors.basePackage("com.zjh.controller"))
                // 指定扫描的请求路径 其他的不扫描
                // .paths(PathSelectors.ant("/user/**"))
                .build();

    }

    private ApiInfo apiInfo() {

        //作者信息
        Contact contact = new Contact("wo", "http://localhost:8080/hello", "123@qq.com");

        return new ApiInfo(
                "Api接口文档",
                "这是一个描述",
                "1.0",
                "https://www.kuangstudy.com/",
                contact,
                "Apache 2.0",
                "http://www.apache.org/licenses/LICENSE-2.0",
                new ArrayList<>());
    }

}
